/* eslint no-unused-vars:0 */
import React from 'react';
import { Form, Input, Select } from 'antd';
import './index.less';
// 由于 antd 组件的默认文案是英文，所以需要修改为中文
import 'moment/locale/zh-cn';
import 'antd/dist/antd.css';

//form代码，没有什么改进，把下面的提交按钮去掉就行
class UpdateRiskForm extends React.Component {
    constructor(props) {
        // riskId
        super(props);
        this.state = {
            riskTypes: [{ id: 123 }, { status: '网络忙' }],
            riskLevels: [{ id: 123 }, { status: '网络忙' }],
            dealStatus: [{ id: 123 }, { status: '网络忙' }]
        };
    }

    findRiskTypes() {
        this.$get('/risk/findAllRiskTypes')
            .then((res) => {
                this.setState({
                    riskTypes: res.riskTypes
                });
            })
            .catch((e) => {
                console.log(e);
            });
    }

    findLevelTypes() {
        this.$get('/risk/findAllRiskLevels')
            .then((res) => {
                this.setState({
                    riskLevels: res.riskLevels
                });
            })
            .catch((e) => {
                console.log(e);
            });
    }
    // /riskSolution/findAllDealStatus
    //allDealStatus
    findAllDealStatus() {
        this.$get('/riskSolution/findAllDealStatus')
            .then((res) => {
                console.log(res);
                this.setState({
                    dealStatus: res.allDealStatus
                });
            })
            .catch((e) => {
                console.log(e);
            });
    }
    componentWillMount() {
        this.findRiskTypes();
        this.findLevelTypes();
        this.findAllDealStatus();
    }

    render() {
        const { getFieldDecorator } = this.props.form;

        const formItemLayout = {
            labelCol: {
                xs: { span: 100 },
                sm: { span: 100 }
            },
            wrapperCol: {
                xs: { span: 100 },
                sm: { span: 100 }
            }
        };

        return (
            <Form {...formItemLayout}>
                <Form.Item label="标题" layout="inline">
                    {getFieldDecorator('title', {
                        initialValue: this.props.title,
                        rules: [
                            {
                                required: true,
                                message: '请输入风险事件标题'
                            }
                        ]
                    })(<Input />)}
                </Form.Item>
                <Form.Item label="事件内容" layout="inline">
                    {getFieldDecorator('content', {
                        initialValue: this.props.content,
                        rules: [
                            {
                                required: false
                            }
                        ]
                    })(<Input />)}
                </Form.Item>
                <Form.Item label="风险事件种类">
                    {getFieldDecorator('type', {
                        rules: [
                            {
                                required: true,
                                message: '请选择风险事件种类'
                            }
                        ]
                    })(
                        <Select
                            className="sub-row2-select"
                            placeholder="请选择"
                            labelInValue
                            style={{ width: 200, height: 30 }}>
                            {this.state.riskTypes.map((item) => {
                                return (
                                    <Select.Option
                                        key={item.id}
                                        value={item.type}>
                                        {item.type}
                                    </Select.Option>
                                );
                            })}
                        </Select>
                    )}
                </Form.Item>
                <Form.Item label="预警级别">
                    {getFieldDecorator('level', {
                        rules: [
                            {
                                required: true,
                                message: '请选择预警级别'
                            }
                        ]
                    })(
                        <Select
                            className="sub-row2-select"
                            placeholder="请选择"
                            labelInValue
                            style={{ width: 200, height: 30 }}>
                            {this.state.riskLevels.map((item) => {
                                return (
                                    <Select.Option
                                        key={item.id}
                                        value={item.level}>
                                        {item.level}
                                    </Select.Option>
                                );
                            })}
                        </Select>
                    )}
                </Form.Item>
                <Form.Item label="解决状态">
                    {getFieldDecorator('status', {
                        rules: [
                            {
                                required: true,
                                message: '请选择解决状态'
                            }
                        ]
                    })(
                        <Select
                            className="sub-row2-select"
                            placeholder="请选择"
                            labelInValue
                            style={{ width: 200, height: 30 }}>
                            {this.state.dealStatus.map((item) => {
                                return (
                                    <Select.Option
                                        key={item.id}
                                        value={item.status}>
                                        {item.status}
                                    </Select.Option>
                                );
                            })}
                        </Select>
                    )}
                </Form.Item>
                <Form.Item label="来源媒体类型">
                    {getFieldDecorator('mediaType', {
                        initialValue: this.props.mediaType,
                        rules: [
                            {
                                required: false
                            }
                        ]
                    })(<Input />)}
                </Form.Item>
                <Form.Item label="来源媒体">
                    {getFieldDecorator('fromMedia', {
                        initialValue: this.props.fromMedia,
                        rules: [
                            {
                                required: false
                            }
                        ]
                    })(<Input />)}
                </Form.Item>
                <Form.Item label="来源作者">
                    {getFieldDecorator('fromAuthor', {
                        initialValue: this.props.fromAuthor,
                        rules: [
                            {
                                required: false
                            }
                        ]
                    })(<Input />)}
                </Form.Item>
                <Form.Item label="转发量">
                    {getFieldDecorator('forward', {
                        initialValue: this.props.forward,
                        rules: [
                            {
                                required: false
                            }
                        ]
                    })(<Input />)}
                </Form.Item>
                <Form.Item label="关注量">
                    {getFieldDecorator('follow', {
                        initialValue: this.props.follow,
                        rules: [
                            {
                                required: false
                            }
                        ]
                    })(<Input />)}
                </Form.Item>
                <Form.Item label="打标签(用于识别同类事件)">
                    {getFieldDecorator('tipFlag', {
                        initialValue: this.props.tipFlag,
                        rules: [
                            {
                                required: false
                            }
                        ]
                    })(<Input />)}
                </Form.Item>
                <Form.Item label="外部链接">
                    {getFieldDecorator('url', {
                        initialValue: this.props.url,
                        rules: [
                            {
                                required: false
                            }
                        ]
                    })(<Input />)}
                </Form.Item>
            </Form>
        );
    }
}

const WrappedUpdateRiskFormForm = Form.create()(UpdateRiskForm);

export default WrappedUpdateRiskFormForm;
